package com.ychug.gateway.cms;

import java.util.List;

import com.ychug.framework.business.service.SystemSerialNumber;
import com.ychug.service.cms.entity.CmsAttributeEntity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ychug.service.cms.service.ICmsAttributeService;
import com.ychug.framework.web.base.BaseController;
import com.ychug.framework.web.page.TableDataInfo;
import com.ychug.common.base.ResultAjaxHash;

/**
 * 文档属性 信息操作处理
 * 
 * @author mcpcms
 * @date 2019-07-13
 */
@Controller
@RequestMapping("/cms/cmsAttribute")
public class CmsAttributeController extends BaseController
{
    private String prefix = "modules/cms/attribute";
	
	@Autowired
	private ICmsAttributeService cmsAttributeService;

	@Autowired
	private SystemSerialNumber systemSerialNumber;

	@GetMapping()
	public String cmsAttribute()
	{
	    return prefix + "/viewAttribute";
	}
	
	/**
	 * 查询文档属性列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CmsAttributeEntity cmsAttribute)
	{
		startPage();
        List<CmsAttributeEntity> list = cmsAttributeService.selectCmsAttributeList(cmsAttribute);
		return getDataTable(list);
	}
	
	/**
	 * 新增文档属性
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/addAttribute";
	}
	
	/**
	 * 新增保存文档属性
	 */
	@PostMapping("/add")
	@ResponseBody
	public ResultAjaxHash addSave(CmsAttributeEntity cmsAttribute)
	{
		String attrId = systemSerialNumber.createSerialNumber("AttrNo","CMS");
		cmsAttribute.setAttrId(Long.parseLong(attrId));
		cmsAttribute.setSiteId(getCmsSiteEntity().getSiteId().longValue());
		return toAjax(cmsAttributeService.insertCmsAttribute(cmsAttribute));
	}

	/**
	 * 修改文档属性
	 */
	@GetMapping("/edit/{attrId}")
	public String edit(@PathVariable("attrId") Long attrId, ModelMap mmap)
	{
		CmsAttributeEntity cmsAttribute = cmsAttributeService.selectCmsAttributeById(attrId);
		mmap.put("cmsAttribute", cmsAttribute);
	    return prefix + "/editAttribute";
	}
	
	/**
	 * 修改保存文档属性
	 */
	@PostMapping("/edit")
	@ResponseBody
	public ResultAjaxHash editSave(CmsAttributeEntity cmsAttribute)
	{		
		return toAjax(cmsAttributeService.updateCmsAttribute(cmsAttribute));
	}
	
	/**
	 * 删除文档属性
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public ResultAjaxHash remove(String ids)
	{		
		return toAjax(cmsAttributeService.deleteCmsAttributeByIds(ids));
	}
	
}
